package com.jsu.forum.controller.v1;

import com.jsu.forum.service.impl.PassageServiceImpl;
import com.jsu.forum.service.impl.SearchServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.example.model.common.dtos.ResponseResult;
import org.example.model.forum.dto.ForumDto;
import org.example.model.forum.dto.PassageDto;
import org.example.model.forum.pojo.Passage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/web/v1/passage")
@Api(tags = "论坛文章控制器")
public class PassageController {
    @Autowired
    private PassageServiceImpl passageService;
    @Autowired
    private SearchServiceImpl searchService;

    @ApiOperation(value = "添加文章")
    @PostMapping("/add")
    public ResponseResult addPassage(@RequestBody ForumDto forumDto){
        return passageService.addPassage(forumDto);
    }

    @ApiOperation(value = "获取文章")
    @PostMapping("/get")
    public ResponseResult getPassage(@RequestBody PassageDto passageDto,@RequestHeader("token") String token){
        return passageService.getPassage(passageDto,token);
    }

    @ApiOperation(value = "修改文章")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deletePassage(@PathVariable Integer id){
        return passageService.deletePassage(id);
    }

    @ApiOperation(value = "更新浏览量")
    @PostMapping("/add/count/{id}")
    public ResponseResult addCount(@PathVariable Integer id){
        return passageService.addCount(id);
    }

    @ApiOperation(value = "模糊查询")
    @GetMapping("/search/{keyword}")
    public ResponseResult searchPassage(@PathVariable String keyword){
        return searchService.searchPassage(keyword);
    }

    @ApiOperation(value = "获取搜索词条")
    @GetMapping("/search/history/{keyword}")
    public ResponseResult getSearchHistory(@PathVariable String keyword){
        return searchService.searchKeywords(keyword);
    }

    @ApiOperation(value = "获取搜索热词")
    @GetMapping("/search/hot")
    public ResponseResult getHotSearch(){
        return searchService.getHotSearch();
    }
}
